class Session {

    static getInstance(){
        if( !Session.instance ){
             Session.instance = new Session();
        }
        return Session.instance;
    }

    getSessionKeyPrefix(){
        return new Date().toLocaleDateString();
    }



    /**
     * 保存被剔除的配送点到session
     * @param value
     * @returns {boolean}
     */
    saveRouteRemovePoints( value ){
        var k = 'routerWayPoints';
        let arr=[];
        let get = this.getRouteRemovePoints();
        let valueLat = value.lat;
        let valueLng = value.lng;
        if(!get){
            arr.push(value)
            value = JSON.stringify( arr );
            sessionStorage.setItem(k,value)  ;
            return false;
        }
        for( let i=0;i<get.length;i++ ) {
            if( get[i].lat==valueLat && get[i].lng== valueLng ) {
                return false;
            }

        }
        get.push( value );
        sessionStorage.setItem(k , JSON.stringify( get )) ;
    }

    /**
     * 从session中移除剔除的路由
     * @param value
     * @returns {boolean}
     */
    deleteRouteRemovePoints ( value ) {   // not use
        let k = 'routerWayPoints';
        let get = this.getRouteRemovePoints();
        let valueLat = value.lat;
        let valueLng = value.lng;
        let ret = [];
        if( get == null) {
            return false;
        }
        for (let i=0; i<get.length; i++ ) {
            if(valueLat !=  get[i].lat && valueLng != get[i].lng) {
                var t={};
                t= get[i];
                ret.push(t);
            }
        }
        return sessionStorage.setItem( k , JSON.stringify( ret ))
    }

    /**
     * 获取被剔除的配送点到session
     * @param value
     * @returns {boolean}
     */
    getRouteRemovePoints(){
        let  ret = sessionStorage.getItem('routerWayPoints');
        if( ret ) {
            return JSON.parse( ret );
        }
        return null;
    }

    /**
     * 保存路线的每个地点
     * @param routerId
     * @param data
     */
    saveRoutePoints (routerId , data) {
        return sessionStorage.setItem( routerId , JSON.stringify(data) );
    }
    /**
     * 获取路线的每个地点
     * @param routerId
     * @param data
     */
    getRoutePoints ( routerId) {
        let ret = sessionStorage.getItem( routerId );
        return ret ? JSON.parse( ret ) : null;

    }
}